package com.koron.order.perambulate.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.github.pagehelper.PageHelper;
import com.koron.common.core.util.StringUtils;
import com.koron.order.perambulate.bean.query.CheckQuery;
import com.koron.order.perambulate.bean.query.LinePeramQuery;
import com.koron.order.perambulate.bean.query.PeramOrderQuery;
import com.koron.order.perambulate.bean.vo.LineMonitorVo;
import com.koron.order.perambulate.bean.vo.LinePerambulateVo;
import com.koron.order.perambulate.bean.vo.MonitorChangeVo;
import com.koron.order.perambulate.bean.vo.PerambulateOrderVo;
import com.koron.order.perambulate.mapper.PerambulateMapper;
import com.koron.order.perambulate.service.LinePerambulateService;
import com.koron.order.risk.base.bean.po.LineRisk;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: LinePerambulateServiceImpl
 * @Description:
 * @Date: 2023/2/1
 * @Author: 李一辰
 * @Version: 1.0
 **/
@Service
public class LinePerambulateServiceImpl implements LinePerambulateService {

    @Override
    @TaskAnnotation("list")
    public List<LinePeramQuery> list(SessionFactory factory, LinePeramQuery linePeramQuery) {
        PerambulateMapper mapper = factory.getMapper(PerambulateMapper.class);
        PageHelper.startPage(linePeramQuery.getPage(),linePeramQuery.getPageSize(),linePeramQuery.getOrderBy());
        List<LinePeramQuery> list = mapper.list(linePeramQuery);
        return list;
    }
    @Override
    @TaskAnnotation("getLinePeramDetailById")
    public LinePeramQuery getLinePeramDetailById(SessionFactory sessionFactory, String id) {
        PerambulateMapper mapper = sessionFactory.getMapper(PerambulateMapper.class);
        LinePeramQuery linPeramDetail = mapper.getLinePeramDetailById(id);
        return linPeramDetail;
    }

    @Override
    @TaskAnnotation("BatchInsert")
    public Integer BatchInsert(SessionFactory sessionFactory, List<LinePerambulateVo> list) {
        if (CollUtil.isEmpty(list)) {
            return 0;
        }
        PerambulateMapper mapper = sessionFactory.getMapper(PerambulateMapper.class);
        Integer integer = mapper.BatchInsert(list);
        return integer;
    }

    @Override
    @TaskAnnotation("getRiskSubandKeyword")
    public List<LineRisk> getRiskSubandKeyword(SessionFactory factory) {
        PerambulateMapper mapper = factory.getMapper(PerambulateMapper.class);
        List<LineRisk> riskSubandKeyword = mapper.getRiskSubandKeyword();
        return riskSubandKeyword;
    }

    @Override
    @TaskAnnotation("getPeramList")
    public List<PerambulateOrderVo> getPeramList(SessionFactory factory, PeramOrderQuery peramOrderQuery) {
        PerambulateMapper mapper = factory.getMapper(PerambulateMapper.class);
        PageHelper.startPage(peramOrderQuery.getPage(),peramOrderQuery.getPageSize(),peramOrderQuery.getOrderBy());
        List<PerambulateOrderVo> peramList = mapper.getPeramList(peramOrderQuery);
        return peramList;
    }

    @Override
    @TaskAnnotation("insert")
    public Integer insert(SessionFactory factory, PerambulateOrderVo perambulateOrderVo) {
        PerambulateMapper mapper = factory.getMapper(PerambulateMapper.class);
        Integer insert = mapper.insert(perambulateOrderVo);
        return insert;
    }
    @Override
    @TaskAnnotation("BatchInsert1")
    public Integer BatchInsert1(SessionFactory sessionFactory, List<MonitorChangeVo> monitorChangeVos) {
        if(CollUtil.isEmpty(monitorChangeVos)){
            return  0;
        }
        PerambulateMapper mapper = sessionFactory.getMapper(PerambulateMapper.class);
        Integer integer = mapper.BatchInsert1(monitorChangeVos);
        return integer;
    }

    @Override
    @TaskAnnotation("getDeptByIdAndParamId")
    public String getDeptByIdAndParamId(SessionFactory sessionFactory, String id, String typeId) {
        PerambulateMapper mapper = sessionFactory.getMapper(PerambulateMapper.class);
        String paramId = mapper.getParamId(typeId);
        if(paramId == null){
            return null;
        }
        String dept = mapper.getDeptByIdAndParamId(id, paramId);
        return dept;
    }

    @Override
    @TaskAnnotation("InsertSinglePerm")
    public Integer InsertSinglePerm(SessionFactory sessionFactory, LinePerambulateVo linePerambulateVo) {
        PerambulateMapper mapper = sessionFactory.getMapper(PerambulateMapper.class);
        if(StringUtils.isNull(linePerambulateVo)){
            return  0;
        }
        return mapper.InsertSinglePerm(linePerambulateVo);
    }


    @Override
    @TaskAnnotation("monitorList")
    public List<LineMonitorVo> monitorList(SessionFactory sessionFactory, CheckQuery checkQuery) {
        checkQuery.getOrders().get(0).setPrefix("l");
        PerambulateMapper mapper = sessionFactory.getMapper(PerambulateMapper.class);
        PageHelper.startPage(checkQuery.getPage(),checkQuery.getPageSize(),checkQuery.getOrderBy());
        List<LineMonitorVo> lineMonitorVos = mapper.monitorList(checkQuery);
        return lineMonitorVos;
    }

    @Override
    @TaskAnnotation("getMonitorDetailById")
    public LineMonitorVo getMonitorDetailById(SessionFactory sessionFactory, String id) {
        PerambulateMapper mapper = sessionFactory.getMapper(PerambulateMapper.class);
        LineMonitorVo monitorVo = mapper.getMonitorDetailById(id);
        return monitorVo;
    }







}
